<template>
  <div class="search-result-box">
    <div class="result-container" v-for="item in pageItems" :key="item.id">
      <search-result-item
        :id="item.id"
        :date="item.createTime"
        :content=getContent(item)
        :label="item.fileName"
      ></search-result-item>
    </div>
    <el-pagination
      background
      :current-page="page"
      :page-size="size"
      @current-change="currentChange"
      layout="prev, pager, next"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import SearchResultItem from "@/components/Search/Result/Item/SearchResultItem.vue";

export default {
  components: { SearchResultItem },
  props: {
    searchType: { required: true, type: String },
    pageItems: { required: true, type: Array },
    total: { required: true, type: Number },
    query: {type: String},
  },
  data() {
    return {
      page: 1,
      size: 12,
    };
  },
  methods: {
    //获取搜索结果内容
    //根据文件类型判断显示简介还是文件内容
    getContent(item) {
      console.log(this.query)
      if (item.fileSuffix === "rar" || item.fileSuffix === "zip")
        return item.fileIntro;
      else if (this.query.indexOf(item.fileName)!=-1)
        return item.fileIntro;
      else
        return item.fileContent;
    },
    //获取当前页数内容
    getPageItems() {
      this.$emit("get-" + this.searchType + "-search-data", this.page);
    },
    //页码变化获取数据
    currentChange(val) {
      this.page = val;
      this.getPageItems();
    },
  },
};
</script>

<style scoped>
.search-result-box {
  text-align: left;
}
.result-container {
  margin-left: 16px;
  margin-top: 18px;
  width: 760px;
  min-height: 100px;
}
.el-pagination.is-background {
  margin: 64px 0;
}
</style>
